package com.leo.oplayer.filter.bak;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.util.Log;
import android.widget.Toast;

public class SmsReceiver extends BroadcastReceiver {
	 private static final String TAG = "SmsReceiver";
	
	 String receiveMsg = "";
     public void onReceive(Context context, Intent intent)
     {
       SmsMessage[] msg= null;            
       if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
       {
             //StringBuilder buf = new StringBuilder();
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                    Object[] pdusObj = (Object[]) bundle.get("pdus");
                    msg= new SmsMessage[pdusObj.length];
                    for (int i = 0; i<pdusObj.length; i++)
                            msg[i] = SmsMessage.createFromPdu ((byte[]) pdusObj[i]);
            }

        for(int i = 0; i < msg.length; i++)
        {            
            String msgTxt = msg[i].getOriginatingAddress() + "@"+ msg[i].getMessageBody();
            Log.v(TAG, msgTxt);           
            Toast.makeText(context, msgTxt, Toast.LENGTH_LONG).show();//收到短信后显示到屏幕上
            return;
        }
        return;
       }
     }   
}
